btrfs-balance-least-used: sort block groups by bytes used, not percentage used#33
btrfs-balance-least-used: sort block groups by bytes used, not percentage used#33intelfx wants to merge 2 commits intoknorrie:masterfrom
Conversation
…tage used This way, we can quickly clean up completely empty block groups. Additionally, if `btrfs-balance-least-used -u 0` is invoked, only consider fully empty block groups because this seems a useful edge case (there can be a lot of almost-empty block groups which are technically used_pct==0 but still take a lot of time to balance, so the user may as well invoke with `-u 1`).
|
Hi! That's interesting. Do I understand correctly that:
This question because the title of the whole merge request is "sort block groups by bytes used, not percentage". |
|
Ok, I think I figured out what happens here. So, the current code for @property
def used_pct(self):
"""Convenience property that calculates the percentage of usage."""
return int(round((self.used * 100) / self.length))(side note: the The When writing However, the suggested improvement to use actual bytes used also has a problem, because block groups can have different sizes. We'd rather first reclaim the unused space in a 10GiB RAID0 bg with 1023MiB used (~10%), than a 1GiB RAID0 bg with 1023MiB used (~100%). If I try to think as a new user who uses
Does this make sense? So, neither #!/usr/bin/python3
import math
SZ_1M = 0x00100000
SZ_1G = 0x40000000
def bla(used, length, fn):
float_pct = (used * 100) / length
print("{} {} {}".format(used, float_pct, fn(float_pct)))
def doit(fn):
bla(0, SZ_1G, fn)
bla(SZ_1M, SZ_1G, fn)
bla(8 * SZ_1M, SZ_1G, fn)
bla(1019 * SZ_1M, SZ_1G, fn)
bla(1024 * SZ_1M, SZ_1G, fn)
print("h'okay, so, what a 1GiB BlockGroupItem used_pct does now is:")
doit(round)
print()
def yolo(float_pct):
if float_pct < 50:
return math.ceil(float_pct)
return math.floor(float_pct)
print("why not this:")
doit(yolo)output: |
|
@intelfx What do you think of the above suggestion to always make 0% really 0% and 100% really exactly 100%? |
|
I still like this idea ("make 0% really 0%) and will implement this. |
This way, we can quickly clean up completely empty block groups.
Additionally, if
btrfs-balance-least-used -u 0is invoked, onlyconsider fully empty block groups because this seems a useful edge case
(there can be a lot of almost-empty block groups which are technically
used_pct==0 but still take a lot of time to balance, so the user may as
well invoke with
-u 1).